<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>范例</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="sphinx.constants.html">预定义常量</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.sphinxclient.html">SphinxClient</a></div>
 <div class="up"><a href="book.sphinx.html">Sphinx</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="sphinx.examples" class="chapter">
 <h1>范例</h1>

 <div class="example" id="example-4634">
  <p><strong>Example #1 基本使用范例</strong></p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$s&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SphinxClient</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$s</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setServer</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">6712</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$s</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setMatchMode</span><span style="color: #007700">(</span><span style="color: #0000BB">SPH_MATCH_ANY</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$s</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setMaxQueryTime</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$s</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
array(10) {
  [&quot;error&quot;]=&gt;
  string(0) &quot;&quot;
  [&quot;warning&quot;]=&gt;
  string(0) &quot;&quot;
  [&quot;status&quot;]=&gt;
  int(0)
  [&quot;fields&quot;]=&gt;
  array(3) {
    [0]=&gt;
    string(7) &quot;subject&quot;
    [1]=&gt;
    string(4) &quot;body&quot;
    [2]=&gt;
    string(6) &quot;author&quot;
  }
  [&quot;attrs&quot;]=&gt;
  array(0) {
  }
  [&quot;matches&quot;]=&gt;
  array(1) {
    [3]=&gt;
    array(2) {
      [&quot;weight&quot;]=&gt;
      int(1)
      [&quot;attrs&quot;]=&gt;
      array(0) {
      }
    }
  }
  [&quot;total&quot;]=&gt;
  int(1)
  [&quot;total_found&quot;]=&gt;
  int(1)
  [&quot;time&quot;]=&gt;
  float(0)
  [&quot;words&quot;]=&gt;
  array(1) {
    [&quot;to&quot;]=&gt;
    array(2) {
      [&quot;docs&quot;]=&gt;
      int(1)
      [&quot;hits&quot;]=&gt;
      int(1)
    }
  }
}
</pre></div>
  </div>
 </div>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="sphinx.constants.html">预定义常量</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.sphinxclient.html">SphinxClient</a></div>
 <div class="up"><a href="book.sphinx.html">Sphinx</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
